package com.yhb.channel;

import com.yhb.channel.impl.ANYPAY.AnyPayChannel;
import com.yhb.channel.impl.ANYPAY.AnyPayDHL09Channel;
import com.yhb.channel.impl.ANYPAY.AnyPayDHLChannel;
import com.yhb.channel.impl.ANYPAY.AnyPayTXChannel;
import com.yhb.channel.impl.MOCK.MockChannel;
import com.yhb.channel.impl.SXY.SXYChannel;
import com.yhb.channel.impl.YPL.YPLChannel;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("ChannelFactory")
public class ChannelFactory {

    @Autowired
    private MockChannel mockChannel;

    @Autowired
    private SXYChannel sxyChannel;

    @Autowired
    private YPLChannel yplChannel;

    @Autowired
    private AnyPayChannel anyPayChannel;

    @Autowired
    private AnyPayTXChannel anyPayTXChannel;

    @Autowired
    private AnyPayDHLChannel anyPayDHLChannel;

    @Autowired
    private AnyPayDHL09Channel anyPayDHL09Channel;

    public static final String MOCK = "MOCK"; // mock联调专用通道
    public static final String SXY = "SXY"; // 首信易
    public static final String YPL = "YPL"; // 易票联
    public static final String BJCJ = "BJCJ"; // 北京畅捷
    public static final String SCALABLE = "SCALABLE"; // 第三方扩展
    public static final String ANYPAY = "ANYPAY"; // 北京易宝anypay小额DH
    public static final String ANYPAY_DHL = "ANYPAY_DHL"; // 北京易宝anypay大额DH
    public static final String ANYPAY_DHL09 = "ANYPAY_DHL09"; // 北京易宝anypay大额DH
    public static final String ANYPAY_TX = "ANYPAY-LARGE_CHANNEL07"; // 北京易宝anypay套现

    public PayChannel getChannelByType(@NotNull String name) {
        if (MOCK.equals(name)) {
            return mockChannel;
        }
        if (SXY.equals(name)) {
            return sxyChannel;
        }
        if (YPL.equals(name)) {
            return yplChannel;
        }
        if (ANYPAY.equals(name)) {
            if (anyPayChannel == null) {
                throw new RuntimeException("anyPayChannel is null");
            }
            return anyPayChannel;
        }
        if (ANYPAY_TX.equals(name)) {
            if (anyPayTXChannel == null) {
                throw new RuntimeException("anyPayTXChannel is null");
            }
            return anyPayTXChannel;
        }
        if (ANYPAY_DHL.equals(name)) {
            if (anyPayDHLChannel == null) {
                throw new RuntimeException("anyPayDHLChannel is null");
            }
            return anyPayDHLChannel;
        }
        if (ANYPAY_DHL09.equals(name)) {
            if (anyPayDHL09Channel == null) {
                throw new RuntimeException("anyPayDHL09Channel is null");
            }
            return anyPayDHL09Channel;
        }
        throw new RuntimeException("channel type " + name + "not implemented");
    }
}
